from django.db import models


class Cate(models.Model):
    name = models.CharField('分类名',max_length=20)

    class Meta:
        db_table = 'cates'
        verbose_name = '分类表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Goods(models.Model):
    name = models.CharField('商品名', max_length=20)
    desc = models.CharField('简介', max_length=200)
    price = models.DecimalField('价格', max_digits=6, decimal_places=2)
    unit = models.CharField('单位', max_length=20)
    store = models.IntegerField('库存')
    cate = models.ForeignKey(Cate, on_delete=models.CASCADE, verbose_name="所属分类")
    pic = models.ImageField(upload_to="static/pic", verbose_name="首图")
    content = models.TextField('内容')

    class Meta:
        db_table = "goods"
        verbose_name = "商品表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
